﻿var service = (function () {
    function callService(_fn, _rt, _uid, _tid, _did, _dt, _xd, _mod) {
        try {
            var servicePath = getServicePath(_fn);
            var data = {};
            if (_fn == "getdata") {
                data.UserID = _uid;
                data.TaskGuid = _tid;
                data.DataGuid = _did;
                data.DataType = _dt;
            }
            else if (_fn == "setdata") {
                data.UserID = _uid;
                data.TaskGuid = _tid;
                data.DataGuid = _did;
                data.DataType = _dt;
                data.xmlData = _xd;
            }
            else if (_fn == "transformdata") {
                data.UserID = _uid;
                data.TaskGuid = _tid;
                data.xmlData = _xd;
            }

            $.ajax({
                type: _rt,
                url: servicePath,
                data: data,
                async: _mod,
                beforeSend: function () {
                },
                success: function (request, textStatus) {
                    return request.text;
                },
                error: function (request, textStatus) {
                    alert(2);
                }
            });

        } catch (e) {
            com._cLog("callService" + e.description, "error");
        }
    }

    function getNewGuid() {

    }

    function getCurrentTime() {
        try {
            var _currentTime = soul.services.time;
            callService("getdata", "", _currentTime.taskguid, _currentTime.dataguid, _currentTime.datatype, null, false);
        } catch (e) {
            com._cLog("getCurrentTime" + e.description, "error");
        }
    }

    function getdata() {
        
    }

    function getServicePath(_fn) {
        try {
            if (Object.hasOwnProperty.call(soul.services.config, _fn)) {
                return soul.services.config["path"] + "/" + soul.services.config[_fn];
            }
            else {
                throw ("services of soul don't have" + _fn);
            }
        } catch (e) {
            com._cLog("getServicePath" + e.description, "error");
        }
    }

    return {
        CallService: function (_fn, _rt, _uid, _tid, _did, _dt, _xd, _mod) {//sn:service name,fn:function name,rt:request type,uid:userID,tid:taskGuid,did:dataGuid,dt:dataType,xp:xmlData,mod:async
            callService(_fn, _rt, _uid, _tid, _did, _dt, _xd, _mod);
        },
        GetCurrentTime: function () {
            return getCurrentTime();
        }
    }
})();